import onlineImg from '@/assets/car/car_green.png'
import speedImg from '@/assets/car/car_blue.png'
import warnImg from '@/assets/car/car_red.png'
import offlineImg from '@/assets/car/car_gray.png'
import expiredImg from '@/assets/car/ico_car_yellow.png'
import onlineImg2 from '@/assets/car/ico_car_green.png'
import speedImg2 from '@/assets/car/ico_car_blue.png'
import warnImg2 from '@/assets/car/ico_car_red.png'
import offlineImg2 from '@/assets/car/ico_car_gray.png'
import expiredImg2 from '@/assets/car/ico_car_yellow.png'

import car_tree_red from '@/assets/home/car_red.png'
import car_tree_green from '@/assets/home/car_green.png'
import car_tree_grey from '@/assets/home/car_grey.png'
import car_tree_yellow from '@/assets/home/car_yellow.png'
import car_tree_blue from '@/assets/home/car_blue.png'

import constant from "@/utils/constant";




const iconObjArray = [
  {
    online: {
      url: onlineImg,
      size: {
        width: 20,
        height: 36
      }
    },

    speed: {
      url: speedImg,
      size: {
        width: 20,
        height: 36
      }
    },

    warn: {
      url: warnImg,
      size: {
        width: 20,
        height: 36
      }
    },

    offline: {
      url: offlineImg,
      size: {
        width: 20,
        height: 36
      }
    },

    expired: {
      url: expiredImg,
      size: {
        width: 29,
        height: 48
      }
    }
  },
  {
    online: {
      url: onlineImg2,
      size: {
        width: 29,
        height: 48
      }
    },

    speed: {
      url: speedImg2,
      size: {
        width: 29,
        height: 48
      }
    },

    warn: {
      url: warnImg2,
      size: {
        width: 29,
        height: 48
      }
    },

    offline: {
      url: offlineImg2,
      size: {
        width: 29,
        height: 48
      }
    },

    expired: {
      url: expiredImg,
      size: {
        width: 29,
        height: 48
      }
    }
  }
]

export function computeIcon(e: any) {
  // if (icon === -1) {
  //   // @ts-ignore
  //   let img = new Image()
  //   img.src = '/api/file' + e.avatar
  //   // this.pictureHeight.height = Math.ceil(img.height/img.width * 460)+'px'
  //   return {
  //     ignoreDirect: true,
  //     size: {
  //       width: 100,
  //       height: 200
  //     },
  //     url: '/api/file' + e.avatar
  //   }
  // } else {

  // }

  return constant.iconUrl + (e.icon || "car") + "/" + (()=>{
    if (e.alarms && e.alarms[0]) {
      return "red"
    }
    switch (e.connectionStatus) {
      case 'online':
        if (e.speed !== 0) {
          return "green"
        } else {
          return "blue"
        }
      case 'expired':
        return "gray"
      default:
        break
    }
    return "gray"
  })() + ".png"
}


export function computeTreeIcon(e: any) {
  if (e.alarms && e.alarms.length) {
    return car_tree_red
  }
  switch (e.connectionStatus) {
    case 'online':
      if(e.speed > 80){
        return car_tree_yellow
      }else if(e.speed > 0){
        return car_tree_green
      }else {
        return car_tree_blue
      }
    case 'expired':
      return car_tree_grey
    case "offline":
      return car_tree_grey
  }
}
